<?php
use yii\helpers\Url;
use yii\widgets\LinkPager;
?>
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf">操作员列表</div>


                </div>
                <div class="widget-body  am-fr">

                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button id="add" type="button" class="am-btn am-btn-default am-btn-success"><span class="am-icon-plus"></span> 新增</button>

                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                            <input type="text" class="am-form-field ">
                            <span class="am-input-group-btn">
            <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" type="button"></button>
          </span>
                        </div>
                    </div>

                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">
                            <thead>
                            <tr>
                                <th>用户名</th>
                                <th>真实姓名</th>
                                <th>电话</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            foreach ($operators as $operator){ ?>
                                <tr class="gradeX">
                                <td><?=$operator['username']?></td>
                                <td><?=$operator['realname']?></td>
                                <td><?=$operator['phone']?></td>
                                <td><?=date("Y-m-d H:i:s",$operator['createtime'])?></td>
                                <td>
                                    <div class="tpl-table-black-operation">
                                        <a href="<?=Url::to(['user/operator-edit','id'=>$operator['id']])?>">
                                            <i class="am-icon-pencil"></i> 编辑
                                        </a>
                                        <a href="<?=Url::to(['user/operator-reset-password','id'=>$operator['id']])?>">
                                            <i class="am-icon-pencil"></i> 修改密码
                                        </a>
                                        <a href="javascript:;"   class="tpl-table-black-operation-del del" op-id="<?=$operator['id']?>">
                                            <i class="am-icon-trash"></i> 删除
                                        </a>
                                    </div>
                                </td>
                            </tr>
                           <?php }
                            ?>

                            <!-- more data -->
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">

                        <div class="am-fr">
                            <?=LinkPager::widget([
                                'pagination' => $p,
                            ]) ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function(){
        $("#add").click(function(){
            window.location.href="<?=Url::to(['user/operator-add'])?>";
        })
        $(".del").click(function(){
            var id=$(this).attr("op-id");
            $.ajax({
                url:"<?=Url::to(['user/del-operator'])?>",
                data:"id="+id,
                type:'post',
                dataType:'json',
                success:function(data){
                    if(data.status){
                        alert("删除成功");
                        window.location.href="<?=Url::to(['user/operator-list'])?>";
                    }else{
                        alert(data.msg);
                    }
                },
                error:function(){
                    alert("系统繁忙");
                }
            })
        })
    })
</script>